package qlsl.androiddesign.adapter.commonadapter;

import java.util.HashMap;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.adapter.baseadapter.BaseAdapter;
import qlsl.androiddesign.method.AppMethod;
import qlsl.androiddesign.util.commonutil.DensityUtils;

public class MemberCenterAdapter extends BaseAdapter<HashMap<String, Object>> {

	public MemberCenterAdapter(BaseActivity activity, List<HashMap<String, Object>> list) {
		super(activity, list);
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = getItemView(convertView, R.layout.listitem_member_center);

		ViewGroup itemView = getView(convertView, R.id.list_item);
		ImageView iv_icon = getView(convertView, R.id.iv_icon);
		ImageView iv_arrow = getView(convertView, R.id.iv_arrow);
		TextView tv_name = getView(convertView, R.id.tv_text);
		TextView tv_value = getView(convertView, R.id.tv_value);

		HashMap<String, Object> map = getItem(position);
		Integer icon = (Integer) map.get("icon");
		String text = (String) map.get("text");
		int paddingRight = DensityUtils.dp2px(activity, 10);
		int paddingOther = DensityUtils.dp2px(activity, 5);

		tv_name.setText(text);

		if (icon != null) {
			iv_icon.setImageResource(icon);
			iv_icon.setVisibility(View.VISIBLE);
			iv_arrow.setVisibility(View.VISIBLE);
			itemView.setActivated(true);
			itemView.setPadding(0, 0, paddingRight, 0);
		} else {
			iv_icon.setImageResource(0);
			iv_icon.setVisibility(View.GONE);
			iv_arrow.setVisibility(View.GONE);
			itemView.setActivated(false);
			itemView.setPadding(paddingOther, paddingOther, paddingRight, paddingOther);
		}

		if (position == getCount() - 1) {
			LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) itemView.getLayoutParams();
			params.setMargins(0, 0, 0, DensityUtils.dp2px(activity, 10));
		} else {
			LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) itemView.getLayoutParams();
			params.setMargins(0, 0, 0, 0);
		}

		if (text.contains("版本")) {
			tv_value.setText("v" + AppMethod.getAppVersion(activity, activity.getPackageName()));
		} else {
			tv_value.setText("");
		}

		return convertView;
	}

}
